#include "Dosing_Pumps.h";

extern LiquidCrystal     lcd;

prog_char Dosing_Pump_name_1[] PROGMEM = "Alkalinity";
prog_char Dosing_Pump_name_2[] PROGMEM = "Calcium";
prog_char Dosing_Pump_name_3[] PROGMEM = "Magnesium";
prog_char Dosing_Pump_name_4[] PROGMEM = "NO3 PO4-X";
prog_char Dosing_Pump_name_5[] PROGMEM = "Dosing Pump 5";
prog_char Dosing_Pump_name_6[] PROGMEM = "Dosing Pump 6";
prog_char Dosing_Pump_name_7[] PROGMEM = "Dosing Pump 7";
prog_char Dosing_Pump_name_8[] PROGMEM = "Dosing Pump 8";

PROGMEM const char *dosing_pumps_name_table[] = 
{   
  Dosing_Pump_name_1,
  Dosing_Pump_name_2,
  Dosing_Pump_name_3,
  Dosing_Pump_name_4,
  Dosing_Pump_name_5,
  Dosing_Pump_name_6,
  Dosing_Pump_name_7,
  Dosing_Pump_name_8
};


Dosing_Pumps::Dosing_Pumps(){
  for(byte i = 0 ; i <  NUMBER_OF_DOSING_PUMPS ; ++i ){
    Dosing_Pump_arr[i].init(i,PUMPS_FIRST_PIN+i,STIRRER_FIRST_PIN+i);
  }
}

void Dosing_Pumps::Print_Pump_Name(byte Pump_Num){
  strcpy_P(buffer, (char*)pgm_read_word(&(   dosing_pumps_name_table[ Pump_Num ]     )));
  lcd.print(buffer );
}

Dosing_Pump Dosing_Pumps::Get_Dosing_Pump(int index){
  return Dosing_Pump_arr[index];
}

void Dosing_Pumps::Set_Dosing_Pump(int index , Dosing_Pump dosing_pump ){
  int   History = Dosing_Pump_arr[index] .History;
  byte History_l = Dosing_Pump_arr[index] .History_l;
  byte Pump_Liquid_Amount_l_last_time = Dosing_Pump_arr[index] .Pump_Liquid_Amount_l_last_time;
  byte Pump_Liquid_Amount_h_last_time = Dosing_Pump_arr[index] .Pump_Liquid_Amount_h_last_time;
  Dosing_Pump_arr[index] = dosing_pump;
  Dosing_Pump_arr[index].Save_To_EEPROM();

  Dosing_Pump_arr[index].History = History;
  Dosing_Pump_arr[index] .History_l = History_l;
  Dosing_Pump_arr[index] .Pump_Liquid_Amount_l_last_time = Pump_Liquid_Amount_l_last_time;
  Dosing_Pump_arr[index] .Pump_Liquid_Amount_h_last_time = Pump_Liquid_Amount_h_last_time;
}

void Dosing_Pumps::Check_Pumps(){
  for(byte i = 0 ; i <  NUMBER_OF_DOSING_PUMPS ; ++i ){
    Dosing_Pump_arr[i].Check_Pump_programs();
  }
}
void Dosing_Pumps::update_Pumps(bool new_min,bool new_sec){
  for(byte i = 0 ; i <  NUMBER_OF_DOSING_PUMPS ; ++i ){
    Dosing_Pump_arr[i].update(new_min,new_sec);
  }
}

void Dosing_Pumps::Start(byte Pump_Num,byte _Stirrer_Time , byte _Pump_Liquid_Amount_l ,   byte _Pump_Liquid_Amount_h){
  Dosing_Pump_arr[Pump_Num]. Start(_Stirrer_Time , _Pump_Liquid_Amount_l ,   _Pump_Liquid_Amount_h);
}

void  Dosing_Pumps::Start_Pump_Calibration(byte Pump_Num){
  Dosing_Pump_arr[Pump_Num].Start_Pump_Calibration();
}

void  Dosing_Pumps::End_Pump_Calibration(byte Pump_Num){
  Dosing_Pump_arr[Pump_Num].End_Pump_Calibration();
}


void Dosing_Pumps::Print_History(byte Pump_Num){
  Dosing_Pump_arr[Pump_Num].Print_History();
}

void Dosing_Pumps::Clear_History(byte Pump_Num){
  Dosing_Pump_arr[Pump_Num].Clear_History();
}

void Dosing_Pumps::Print_Last_Time(byte Pump_Num){
  Dosing_Pump_arr[Pump_Num].Print_Last_Time();
}












